package com.amarsoft.apot.controller;

import com.amarsoft.apot.service.SendEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/mail")
public class SendMailController {

    // 发件人邮箱
    @Value("${spring.mail.username}")
    private String sendFrom;

    @Autowired
    private SendEmailService sendEmailService;

    /**
     * 单个发送邮件
     */
    @RequestMapping("/sendmail")
    public String sendEmail() {
        String sendTo = "@qq.com";
        String subject = "发送邮件测试";
        String content = "这是一封测试邮件，你看看你收到这个邮箱发送的内容了吗";
        String attachment = null;
        // String attachment = "E:/房补材料-孙智恒110648/个人所得税.pdf";
        sendEmailService.send(sendFrom,sendTo,subject,content,attachment);
        return "邮件发送成功";
    }

    /**
     * 批量发送邮件
     */
    @RequestMapping("/sendmanymail")
    public String sendManyEmail() {
        List<String> sendTos = new ArrayList<>();
//        sendTos.add("934825963@qq.com");
        sendTos.add("1910961676@qq.com");
        String subject = "发送邮件测试";
        String content1 = "这是一封测试邮件，你就看看你收到附件了吗?";
        String content = content1.replace("xxxx", "孙智恒");
        String attachment = "E:/房补材料-孙智恒110648/个人所得税.pdf";

        for(String sendTo : sendTos) {
            sendEmailService.send(sendFrom,sendTo,subject,content,attachment);
        }
        return "邮件发送成功";
    }
}
